import req from "@/uni-sdk/request/request.js";

const Api = {
	classList: "mall-ums/app-api/v1/goods/class",
	goodList: "mall-ums/app-api/v1/goods/classId",
	goodDetail: "mall-ums/app-api/v1/goods/product-detail",

	shoppingCar: "mall-ums/app-api/v1/shopping-carts",
	shoppingCarList: "mall-ums/app-api/v1/shopping-carts/list",
};

export function getClassList(loading = false) {
	return req.commonGet(Api.classList, loading);
}

export function getGoodsByClassId(data) {
	return req.commonGet(Api.goodList, data, false);
}

export function addToShppingCar(data) {
	return req.commonPost(Api.shoppingCar, data, true);
}

export function updateShoppingCar(data) {
	return req.put({
		url: Api.shoppingCar,
		data,
	}, {
		useGlobalLoading: false
	});
}

export function delShoppingCar(id) {
	return req.delete({
		url: Api.shoppingCar + "?id=" + id,
	}, {
		useGlobalLoading: true,
	});
}

export function getShoppingCarList(data, loading = false) {
	return req.commonGet(Api.shoppingCarList, data, loading);
}

export function getGoodDetail(productId) {
	return req.commonGet(Api.goodDetail, {
		productId
	}, true);
}